﻿<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  
  xmlns:sys="clr-namespace:System;assembly=mscorlib"
  
  xmlns:date_time="clr-namespace:System.Controls.DateTime"
  xmlns:controls="clr-namespace:System.Controls">

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Common.xaml"/>
  </ResourceDictionary.MergedDictionaries>

  <sys:String x:Key="days">Days</sys:String>
  
  <ControlTemplate x:Key="controlTemplate" TargetType="date_time:WeekDaysCheckList">

    <Border
      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
      CornerRadius="{TemplateBinding CornerRadius}"
      BorderBrush="{TemplateBinding BorderBrush}"
      BorderThickness="{TemplateBinding BorderThickness}"
      Background="{TemplateBinding Background}" 
      OpacityMask="{TemplateBinding OpacityMask}">

      <WrapPanel>

        <controls:CheckBox
          Content="None"
          Foreground="{TemplateBinding Foreground}"  
          Margin="{TemplateBinding Padding}"
          Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ShowNone, Converter={StaticResource b2v}}"
          IsChecked="{Binding Path=Days, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource e2b}, ConverterParameter=None}"/>

        <controls:CheckBox
          Foreground="{TemplateBinding Foreground}"  
          Margin="{TemplateBinding Padding}"
          Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Culture, Converter={StaticResource c2dn}, ConverterParameter=Sunday}" >
          <controls:CheckBox.IsChecked>
            <MultiBinding Converter="{StaticResource ef2b}" ConverterParameter="Sunday">
              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Days" Mode="TwoWay"/>
              <Binding RelativeSource="{RelativeSource TemplatedParent}" Mode="OneWay"/>
              <Binding Source="{StaticResource days}" Mode="OneWay"/>
            </MultiBinding>
          </controls:CheckBox.IsChecked>
        </controls:CheckBox>

        <controls:CheckBox
			    Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Culture, Converter={StaticResource c2dn}, ConverterParameter=Monday}" 
          Foreground="{TemplateBinding Foreground}" 
          Margin="{TemplateBinding Padding}">
          <controls:CheckBox.IsChecked>
            <MultiBinding Converter="{StaticResource ef2b}" ConverterParameter="Monday">
              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Days" Mode="TwoWay"/>
              <Binding RelativeSource="{RelativeSource TemplatedParent}" Mode="OneWay"/>
              <Binding Source="{StaticResource days}" Mode="OneWay"/>
            </MultiBinding>
          </controls:CheckBox.IsChecked>
        </controls:CheckBox>


        <controls:CheckBox
          Foreground="{TemplateBinding Foreground}" 
          Margin="{TemplateBinding Padding}"
          Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Culture, Converter={StaticResource c2dn}, ConverterParameter=Tuesday}">
          <controls:CheckBox.IsChecked>
            <MultiBinding Converter="{StaticResource ef2b}" ConverterParameter="Tuesday">
              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Days" Mode="TwoWay"/>
              <Binding RelativeSource="{RelativeSource TemplatedParent}" Mode="OneWay"/>
              <Binding Source="{StaticResource days}" Mode="OneWay"/>
            </MultiBinding>
          </controls:CheckBox.IsChecked>
        </controls:CheckBox>

        <controls:CheckBox
			    Foreground="{TemplateBinding Foreground}" 
          Margin="{TemplateBinding Padding}"
          Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Culture, Converter={StaticResource c2dn}, ConverterParameter=Wednesday}">
          <controls:CheckBox.IsChecked>
            <MultiBinding Converter="{StaticResource ef2b}" ConverterParameter="Wednesday">
              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Days" Mode="TwoWay"/>
              <Binding RelativeSource="{RelativeSource TemplatedParent}" Mode="OneWay"/>
              <Binding Source="{StaticResource days}" Mode="OneWay"/>
            </MultiBinding>
          </controls:CheckBox.IsChecked>
        </controls:CheckBox>

        <controls:CheckBox
			    Foreground="{TemplateBinding Foreground}"
          Margin="{TemplateBinding Padding}"
          Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Culture, Converter={StaticResource c2dn}, ConverterParameter=Friday}">
          <controls:CheckBox.IsChecked>
            <MultiBinding Converter="{StaticResource ef2b}" ConverterParameter="Friday">
              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Days" Mode="TwoWay"/>
              <Binding RelativeSource="{RelativeSource TemplatedParent}" Mode="OneWay"/>
              <Binding Source="{StaticResource days}" Mode="OneWay"/>
            </MultiBinding>
          </controls:CheckBox.IsChecked>
        </controls:CheckBox>

        <controls:CheckBox
			    Foreground="{TemplateBinding Foreground}" 
          Margin="{TemplateBinding Padding}"
          Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Culture, Converter={StaticResource c2dn}, ConverterParameter=Saturday}">
          <controls:CheckBox.IsChecked>
            <MultiBinding Converter="{StaticResource ef2b}" ConverterParameter="Saturday">
              <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Days" Mode="TwoWay"/>
              <Binding RelativeSource="{RelativeSource TemplatedParent}" Mode="OneWay"/>
              <Binding Source="{StaticResource days}" Mode="OneWay"/>
            </MultiBinding>
          </controls:CheckBox.IsChecked>
        </controls:CheckBox>

      </WrapPanel>

    </Border>

  </ControlTemplate>


  <Style x:Key="{x:Type date_time:WeekDaysCheckList}" TargetType="date_time:WeekDaysCheckList" BasedOn="{StaticResource {x:Type Control}}">
    <Setter Property="Focusable" Value="False" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="Padding" Value="4"/>
    <Setter Property="Template" Value="{StaticResource controlTemplate}"/>
  </Style>

</ResourceDictionary>